package com.yc.common.exceptions.captcha;

import com.yc.common.constant.HttpStatus;
import com.yc.common.enums.CaptchaType;
import com.yc.common.exceptions.ServiceException;
import lombok.Getter;
import lombok.Setter;

/**
 * 验证码错误异常类
 *
 * @author ruoyi---yanchen
 */

@Getter
@Setter
public class CaptchaException extends ServiceException {
    private static final long serialVersionUID = 1L;

    /**
     * 验证码类型
     */
    private CaptchaType captchaType;

    /**
     * 尝试次数
     */
    private Integer attempts;

    /**
     * 是否锁定
     */
    private Boolean locked;

    /**
     * 剩余尝试次数
     */
    private Integer remainingAttempts;

    /**
     * 错误代码
     */
    private String errorCode;

    /**
     * 默认构造函数
     */
    public CaptchaException() {
        super("验证码错误", HttpStatus.BAD_REQUEST);
        this.captchaType = CaptchaType.IMAGE;
        this.errorCode = "CAPTCHA_ERROR";
    }

    /**
     * 使用自定义消息构造
     *
     * @param message 错误消息
     */
    public CaptchaException(String message) {
        super(message, HttpStatus.BAD_REQUEST);
        this.captchaType = CaptchaType.IMAGE;
        this.errorCode = "CAPTCHA_ERROR";
    }

    /**
     * 完整构造函数
     *
     * @param message           错误消息
     * @param captchaType       验证码类型
     * @param attempts          尝试次数
     * @param remainingAttempts 剩余尝试次数
     * @param locked            是否锁定
     */
    public CaptchaException(String message, CaptchaType captchaType, Integer attempts,
                            Integer remainingAttempts, Boolean locked) {
        super(message, HttpStatus.BAD_REQUEST);
        this.captchaType = captchaType;
        this.attempts = attempts;
        this.remainingAttempts = remainingAttempts;
        this.locked = locked;
        this.errorCode = "CAPTCHA_ERROR";
    }

    /**
     * 带错误代码的构造函数
     *
     * @param message   错误消息
     * @param errorCode 错误代码
     */
    public CaptchaException(String message, String errorCode) {
        super(message, HttpStatus.BAD_REQUEST);
        this.captchaType = CaptchaType.IMAGE;
        this.errorCode = errorCode;
    }
}